<template>
  <div class="seller">
    <scroll ref="scrollX">
      <div class="seller-content">
        <div class="overview">
          <h1 class="title">{{sellerData.name}}</h1>
          <div class="desc">
            <star :size="36" :score="sellerData.score"></star>
            <span class="text">({{sellerData.ratingCount}})</span>
            <span class="text">月售{{sellerData.sellCount}}单</span>
          </div>
          <ul class="remark">
            <li class="block">
              <h2>起送价</h2>
              <div class="content">
                <span class="stress">{{sellerData.minPrice}}</span>元
              </div>
            </li>
            <li class="block">
              <h2>商家配送</h2>
              <div class="content">
                <span class="stress">{{sellerData.deliveryPrice}}</span>元
              </div>
            </li>
            <li class="block">
              <h2>平均配送时间</h2>
              <div class="content">
                <span class="stress">{{sellerData.deliveryTime}}</span>分钟
              </div>
            </li>
          </ul>
          <div class="favorite" @click="toggleFavorite">
            <span class="icon-favorite" :class="{active:favorite}"></span>
            <span class="text">{{favoriteText}}</span>
          </div>
        </div>
        <split></split>
        <div class="bulletin">
          <h1 class="title">公告与活动</h1>
          <div class="content-wrapper">
            <p class="content">{{sellerData.bulletin}}</p>
          </div>
          <ul v-if="sellerData.supports" class="supports">
            <li class="support-item" v-for="(item,index) in sellerData.supports" :key="index">
              <span class="icon" :class="classMap[sellerData.supports[index].type]"></span>
              <span class="text">{{sellerData.supports[index].description}}</span>
            </li>
          </ul>
        </div>
        <split></split>
        <div class="pics">
          <h1 class="title">商家实景</h1>
          <scroll :scrollX="true" :scrollY="false" eventPassthrough="vertical" ref="scrollY">
            <ul class="pic-list" ref="piclist">
              <li class="pic-item" v-for="(item,index) in sellerData.pics" :key="index">
                <img :src="item" />
              </li>
            </ul>
          </scroll>
        </div>
        <split></split>
        <div class="info">
          <h1 class="title">商家信息</h1>
          <ul>
            <li class="info-item" v-for="(info,index) in sellerData.infos" :key="index">{{info}}</li>
          </ul>
        </div>
      </div>
    </scroll>
  </div>
</template>

<script>
import { sellerData } from "../../network/seller";
import star from "../../components/content/star/star";
import split from "../../components/content/split/split";
import scroll from "../../components/common/scroll/scroll";
export default {
  name: "seller",
  components: {
    star,
    split,
    scroll
  },
  data() {
    return {
      sellerData: {},
      classMap: [],
      picwidth: 0,
      favorite: false
    };
  },
  computed: {
    favoriteText() {
      return this.favorite ? "已收藏" : "收藏";
    }
  },
  methods: {
    scrolly() {
      let picWidth = 120;
      let margin = 6;
      let width = (picWidth + margin) * this.sellerData.pics.length - margin;
      this.picwidth = (width / 375) * 100 + "vw";
      this.$refs.piclist.style.width = this.picwidth;
    },
    toggleFavorite() {
      this.favorite = !this.favorite;
    }
  },
  created() {
    sellerData().then(res => {
      this.sellerData = res.data;
      this.$nextTick(() => {
        this.scrolly();
        this.$refs.scrollY.refresh();
      });
    });
    this.classMap = ["decrease", "discount", "special", "invoice", "guarantee"];
  },
  mounted() {}
};
</script>

<style lang='stylus' scoped>
@import '../../common/stylus/mixins.styl'
.seller
  position: absolute
  top: 175px
  bottom: 0
  left: 0
  width: 100vw
  .wrapper
    height: 100%
    width: 100%
    overflow: hidden
  .overview
    padding: 18px
    position: relative
    .title
      margin-bottom: 8px
      line-height: 14px
      font-size: 14px
      color: rgb(7, 17, 27)
    .desc
      padding-bottom: 18px
      font-size: 0
      border-bottom: 1px solid rgba(7, 17, 27, 0.1)
      .star
        display: inline-block
        vertical-align: top
        line-height: 18px
        margin-right: 8px
      .text
        display: inline-block
        vertical-align: top
        margin-right: 12px
        line-height: 18px
        font-size: 10px
        color: rgb(77, 85, 93)
    .remark
      display: flex
      margin-top: 18px
      .block
        flex: 1
        text-align: center
        border-right: 1px solid rgba(7, 17, 27, 0.1)
        &:last-child
          border: 0
        h2
          margin-bottom: 8px
          line-height: 10px
          font-size: 10px
          color: rgb(147, 153, 159)
        .content
          line-height: 24px
          font-size: 10px
          color: rgb(7, 17, 20)
          .stress
            font-size: 24px
    .favorite
      position: absolute
      right: 11px
      top: 18px
      width: 40px
      text-align: center
      .icon-favorite
        margin-bottom: 4px
        display: block
        line-height: 24px
        font-size: 24px
        color: #d4d6d9
        &.active
          color: rgb(240, 20, 20)
      .text
        line-height: 10px
        font-size: 10px
        color: rgb(77, 85, 93)
  .bulletin
    padding: 18px 18px 0 18px
    .title
      margin-bottom: 8px
      line-height: 14px
      font-size: 14px
      color: rgb(7, 17, 27)
    .content-wrapper
      padding: 0 12px 16px 12px
      border-bottom: 1px solid rgba(7, 17, 27, 0.1)
      .content
        line-height: 24px
        font-size: 12px
        color: rgb(240, 20, 20)
    .supports
      .support-item
        padding: 16px 12px
        font-size: 0
        border-bottom: 1px solid rgba(7, 17, 27, 0.1)
        .icon
          vertical-align: top
          display: inline-block
          vertical-align: top
          margin-right: 6px
          width: 16px
          height: 16px
          background-size: 16px 16px
          background-repeat: no-repeat
          font-size: 12px
          &.decrease
            bgimage('./img/decrease_4')
          &.discount
            bgimage('./img/discount_4')
          &.guarantee
            bgimage('./img/guarantee_4')
          &.invoice
            bgimage('./img/invoice_4')
          &.special
            bgimage('./img/special_4')
        .text
          font-size: 12px
          line-height: 16px
          color: rgb(7, 17, 27)
  .pics
    padding: 18px
    .title
      margin-bottom: 12px
      line-height: 14px
      font-size: 14px
      color: rgb(7, 17, 27)
    .wrapper
      overflow: hidden
      .pic-list
        width: 100%
        white-space: nowrap
        font-size: 0
        .pic-item
          display: inline-block
          margin-right: 6px
          width: 120px
          height: 90px
          &:last-child
            margin: 0
          img
            width: 120px
            height: 90px
  .info
    padding: 18px 18px 0 18px
    .title
      padding-bottom: 12px
      line-height: 14px
      font-size: 14px
      color: rgb(7, 17, 27)
      border-bottom: 1px solid rgba(7, 17, 27, 0.1)
    .info-item
      padding: 16px 12px
      line-height: 16px
      font-size: 12px
      color: rgb(7, 17, 27)
      border-bottom: 1px solid rgba(7, 17, 27, 0.1)
      &:last-child
        border: 0
</style>